package com.xxxcompany.dao.impl;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.xxxcompany.service.IAccountService;
import com.xxxcompany.service.impl.AccountServiceImpl;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TransferFrame extends JFrame {

	private JPanel contentPane;
	private JTextField fromIdTextField;
	private JTextField toIdTextField;
	private JTextField moneyTextField;

	IAccountService aService = new AccountServiceImpl();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TransferFrame frame = new TransferFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TransferFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("\u8F6C\u51FA\u8D26\u53F7");
		lblNewLabel.setBounds(33, 57, 54, 15);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("\u8F6C\u5165\u8D26\u53F7");
		lblNewLabel_1.setBounds(33, 97, 54, 15);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("\u91D1\u989D:");
		lblNewLabel_2.setBounds(33, 141, 54, 15);
		contentPane.add(lblNewLabel_2);
		
		JButton btnNewButton = new JButton("\u8F6C\u8D26");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				// 
				int fromId = Integer.parseInt(fromIdTextField.getText());
				
				int toId = Integer.parseInt(toIdTextField.getText());
				
				int money = Integer.parseInt(moneyTextField.getText());
				
				System.out.println(fromId+">"+toId+":"+money);
				
				boolean result = aService.transfer(fromId, toId, money);
				
				JOptionPane.showMessageDialog(null,result?"ת˳ɹ":"תʧ");
				
				
			}
		});
		btnNewButton.setBounds(65, 196, 93, 23);
		contentPane.add(btnNewButton);
		
		fromIdTextField = new JTextField();
		fromIdTextField.setBounds(107, 54, 66, 21);
		contentPane.add(fromIdTextField);
		fromIdTextField.setColumns(10);
		
		toIdTextField = new JTextField();
		toIdTextField.setBounds(107, 94, 66, 21);
		contentPane.add(toIdTextField);
		toIdTextField.setColumns(10);
		
		moneyTextField = new JTextField();
		moneyTextField.setBounds(107, 138, 66, 21);
		contentPane.add(moneyTextField);
		moneyTextField.setColumns(10);
	}
}